home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Snippets / DirectoryPopup 1.0 / □□□DPSample Source / SimpleAppAEHandlers.c < prev    next >
Text File  |  1996-06-03  |  2KB  |  105 lines

  1. /*
  2.  *    Project:        SimpleApp
  3.  *
  4.  *    Filename:         SimpleAppAEHandlers.c
  5.  *
  6.  *    Author:         Marco Piovanelli
  7.  *
  8.  *    Revision History:
  9.  *
  10.  *            1996.05.24                MP        created this file
  11.  *
  12.  */
  13.  
  14. #include "SimpleApp.h"
  15. #include "Utilities.h"
  16.  
  17. OSErr GotRequiredParams ( const AppleEvent * ae )
  18. {
  19.     DescType returnedType ;
  20.     Size actualSize ;
  21.     OSErr err = noErr ;
  22.  
  23.     err = AEGetAttributePtr ( ae, keyMissedKeywordAttr, typeWildCard, & returnedType, nil, 0, & actualSize ) ;
  24.     
  25.     if ( err == errAEDescNotFound )
  26.         return noErr ;
  27.     else if ( err == noErr )
  28.         return errAEParamMissed ;
  29.     else
  30.         return err ;
  31. }
  32.  
  33. pascal OSErr HandleOpenDoc ( const AppleEvent * ae, AppleEvent * reply, SInt32 refCon )
  34. {
  35. #pragma unused ( reply, refCon )
  36.  
  37.     AEDesc docList ;
  38.     OSErr err = noErr ;
  39.     
  40.     InitDesc ( & docList ) ;
  41.     
  42.     //    extract direct parameter from event (must be a list of aliases)
  43.     if ( ( err = AEGetParamDesc ( ae, keyDirectObject, typeAEList, & docList ) ) != noErr )
  44.         goto cleanup ;
  45.     
  46.     if ( ( err = GotRequiredParams ( ae ) ) != noErr )
  47.         goto cleanup ;
  48.     
  49.     //    count the items in the list of aliases
  50.     SInt32 docCount ;
  51.     if ( ( err = AECountItems ( & docList, & docCount ) ) != noErr )
  52.         goto cleanup ;
  53.     
  54.     //    loop through each alias in the list
  55.     for ( SInt32 docIndex = 1 ; docIndex <= docCount ; docIndex ++ )
  56.     {
  57.         AEKeyword keyword ;
  58.         DescType returnedType ;
  59.         Size returnedSize ;
  60.         FSSpec fileSpec ;
  61.  
  62.         //    get nth item as a file system specification record
  63.         if ( ( err = AEGetNthPtr ( & docList, docIndex, typeFSS, & keyword, & returnedType, & fileSpec, sizeof ( fileSpec ), & returnedSize ) ) != noErr )
  64.             goto cleanup ;
  65.         
  66.         //    open the specified file
  67.         if ( ( err = CreateWindow ( & fileSpec ) ) != noErr )
  68.             goto cleanup ;
  69.     }
  70.  
  71. cleanup:
  72.     ForgetDesc ( & docList ) ;
  73.     return err ;
  74. }
  75.  
  76. pascal OSErr HandleOpenApp ( const AppleEvent * ae, AppleEvent * reply, SInt32 refCon )
  77. {
  78. #pragma unused ( reply, refCon )
  79.  
  80.     OSErr err = noErr ;
  81.  
  82.  
  83.     if ( ( err = GotRequiredParams ( ae ) ) != noErr )
  84.         return err ;
  85.     
  86.     if ( ( err = CreateWindow ( nil ) ) != noErr )
  87.         return err ;
  88.             
  89.     return noErr ;
  90. }
  91.  
  92. pascal OSErr HandleQuit ( const AppleEvent * ae, AppleEvent * reply, SInt32 refCon )
  93. {
  94. #pragma unused ( reply, refCon )
  95.  
  96.     OSErr err = noErr ;
  97.  
  98.     if ( ( err = GotRequiredParams ( ae ) ) != noErr )
  99.         return err ;
  100.     
  101.     gExiting = true ;
  102.     
  103.     return noErr ;
  104. }
  105.